package com.haohope.excel.trans;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import com.haohope.excel.exceptions.ExcelException;

public interface IExcelTrans<T> {
	@SuppressWarnings("rawtypes")
	static Map<String,IExcelTrans> TRANS = new HashMap<String,IExcelTrans>();
	@SuppressWarnings("rawtypes")
	public static IExcelTrans createTrans(Class<? extends IExcelTrans> rule) {
		IExcelTrans ruleObj = TRANS.get(rule.getName());
		Lock lock = new ReentrantLock();
        if (null==ruleObj) {
        	lock.lock();
        	try {
        		if (null==ruleObj) {
        			ruleObj = rule.newInstance();
        			TRANS.put(rule.getName(), ruleObj);
        		}
			} catch (Exception e) {
				e.printStackTrace();
				throw new ExcelException(e.getMessage());
			}finally {
				lock.unlock();
			}
        }
        return ruleObj;
	}
	@SuppressWarnings("rawtypes")
	public String transValue(final String sheetname,final int sheet,final int row,Map<String,String> rowObj,String value,Class clazz,Field field) throws ExcelException;
}
